package com.wyk.controller;

import cn.hutool.core.util.IdUtil;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.wyk.service.FeignHystrixService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.naming.Name;

/**
 * @author WangYuKai
 * @Date 2022/6/23
 * @apiNote
 */
@RestController
@RequestMapping("/consumer")
@DefaultProperties(defaultFallback = "global_fallMethod")// hystrix 全局fallback方法
public class HystrixController {
    //注入service
    @Autowired
    private FeignHystrixService feignHystrixService;

    @GetMapping("/payment/hystrix/{id}")
    public String paymentOk(@PathVariable("id") Integer id){
        return feignHystrixService.paymentOk(id);
    }

    @GetMapping("/payment/hystrix/timeout/{id}")
    @HystrixCommand
/*    @HystrixCommand(fallbackMethod = "paymentInfo_TimeOutHandler",
            commandProperties ={@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value="1500")} )*/
    public String paymentError(@PathVariable("id") Integer id){
        return feignHystrixService.paymentError(id);
    }
    //这个是全局的fallBack解决方法
    public String global_fallMethod(@PathVariable("id") Integer id){
        return "请等下，你超时了哟";
    }

}
